home *** CD-ROM | disk | FTP | other *** search
- /*
- * Comment manipulation commands for EPSILON.
- *
- * Copyright (c) 1985 by David Dyer-Bennet
- * Permission for non-commercial use is hereby granted; all other
- * rights are reserved.
- *
- * Written by David Dyer-Bennet
- * Terrabit Software
- * 4242 Minnehaha Ave S
- * Minneapolis, MN 55406
- * Sysop of Fido 14/341, The Terraboard, (612) 721-8967 3/12/24 24hrs
- * (612) 721-8800 NOT 24 hrs! More like noon to midnight
- */
-
- /*
- * Revision history:
- *
- * Edit Date Who Description
- *
- * Version 1.0
- * 1 3-Jan-86 DD-B Initial creation
- */
-
- /*
- * The general structure:
- *
- * Two basic kinds of comments are recognized: end of line comments,
- * and delimited comments. The former are composed of an initiating
- * character sequence, the comment, and an end-of line. The latter
- * are composed of an initiating character sequence, the comment (with
- * as many embedded end-of-lines as desired), and a terminating
- * character sequence.
- *
- * Currently no provision is made for using auto-fill mode when writing
- * comments. This should be given consideration as an area for future
- * development.
- *
- */
-
- #include <eel.h>
-
- #include "comment.h"
-
- #if 0
- when_loading () /* For testing purposes only */
- {
- use_default = 1;
- comment_recog = strsave ("^(^ \t\n)+((/%* )|(/%*))!(.*)%*/$");
- comment_begin = strsave ("/* ");
- comment_end = strsave (" */");
- comment_limit = 65;
- comment_col = 32;
- use_default = 0;
- }
- #endif
-
- command define_comments ()
- /*
- * Prompt the user for the three fields defining comments. The
- * RE matching a comment should use ! to leave cursor on the first
- * character of the text of the comment.
- */
- {
- char ls [80];
-
- get_string (ls, "RE matching comments: ");
- if (comment_recog) free (comment_recog);
- comment_recog = strsave (ls);
- get_string (ls, "Comment begin sequence: ");
- if (comment_begin) free (comment_begin);
- comment_begin = strsave (ls);
- get_string (ls, "Comment end sequence (optional): ");
- if (comment_end) free (comment_end);
- if (strlen (ls))
- comment_end = strsave (ls);
- else
- comment_end = NULL;
- }
-
- int find_comment ()
- /*
- * Using the value in comment_recog, find a comment on the current
- * line and leave point on the first character of its text. Return
- * the character position of the first character of the comment (which
- * will probably be to the left of point). Don't move point if no
- * comment is to be found.
- */
- {
- int origpoint, beglin, endlin, comment_offset;
- int origpos = point;
- int i;
- char *origbuf = bufname;
- char *cr = comment_recog;
-
- to_end_line(); endlin = point;
- to_begin_line(); beglin = point;
- zap ("work_comment");
- xfer ("work_comment", beglin, endlin);
- bufname = "work_comment";
- point = 0;
- i = re_search (1, cr);
- comment_offset = point;
- bufname = origbuf;
- if (i) {
- point += comment_offset;
- return beglin + matchstart;
- } else
- point = origpos;
- return -1;
- }
-
- command find_make_comment () on reg_tab [ALT(';')]
- /*
- * Find a comment on the current line. If there isn't one, make one
- * starting at comment column, or the next tab-stop thereafter; but
- * don't start one to the right of comment_limit (create blank next line
- * and put comment there instead).
- */
- {
- int i;
-
- i = find_comment ();
- if (i != -1) {
- /* Comment already present, adjust position */
- point = i; /* Go to start of comment */
- delete_horizontal_space ();
- i = current_column ();
- to_column (i > comment_col ?
- i + tab_size - i % tab_size : comment_col);
- find_comment (); /* Get to start of text */
- } else {
- /* No comment present, make one */
- to_end_line();
- if (current_column () > comment_limit) {
- insert ('\n');
- }
- i = current_column ();
- to_column (i > comment_col ?
- i + tab_size - i % tab_size : comment_col);
- stuff (comment_begin);
- i = point;
- if (comment_end) stuff (comment_end);
- point = i;
- }
- }
-
- command down_comment_line () on reg_tab [ALT('\n')], reg_tab [CTRL(ALT('m'))]
- /*
- * Go to the next line, and find or make a comment there.
- */
- {
- nl_forward ();
- find_make_comment ();
- }
-
- command delete_comment () on cx_tab [';']
- /*
- * Delete any comment that may be on the current line. If no comment,
- * don't move cursor.
- */
- {
- int i;
-
- i = find_comment ();
- if (i != -1) {
- point = i;
- delete_horizontal_space ();
- kill_line ();
- }
- }
-
- command dump_comment ()
- {
- say ("recog: %s begin: %s", comment_recog, comment_begin);
- }
-
- /* End of comment.e */
-